#include "global.h"

void kexit(int exitValue)
{
	if ((running->processID == 1) && (running->numChildren > 0))
	{
		printf("  * Process 1 cannot die! He has children!\n");
	}
	else
	{
		s16 i = 0;
		
		printf("  * Task %d: %s\n", running->processID, running->deathCry);
		
		running->status = ZOMBIE;
		running->exitValue = exitValue;
		if (running->numChildren > 0)
		{
			for (i = 0; i < NUM_PROCS; ++i)
			{
				if (processes[i].parentProcessID == running->processID)
				{
					processes[i].parentProcessID = 1;
					++processes[1].numChildren;
				}
			}
		}
		
		wakeup(&processes[running->parentProcessID]);
		tswitch();
	}
}
